<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>进位测试</title>
  </style>
  <style>
    body {
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 600px;
    }
  #app {
    color: lightcoral;
    font-size: 30px;
  }
  button {
    width: 50px;
    height: 30px;
  }
  </style>
  <style id="style"></style>
</head>
<body>
  <div>
    <div id="app" class="">注意观察颜色</div>
    <input id="num" type="number" min="0" max="1024" value="0">
  </div>
  <script>

  num.onchange = function() {
    let total = +num.value;
    app.className = "";
    if(total <= 0) {
      return;
    }
    new Array(total).fill(1).forEach((it, index) => {
      app.classList.add('test-' + index);
    });
    let selector = '.' + Array.from(app.classList).join('.');
    style.innerHTML = `#app.test-0 {color: lightblue;}
#app.test-0.test-1 {color: lightgreen;}
` + selector + `{color: gray;}`;
  }
  </script>
</body>
</html>